package com.fengmi.bloom;

import com.fengmi.consts.RedisKey;
import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BloomConfig {


    @Bean
    public RBloomFilter<Object> bloomFilter(){
        //配置redis
        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.25.130:6379")
        .setPassword("123456");

        //实例化redisson客户端
        RedissonClient redissonClient = Redisson.create(config);


        //实例化bloomfilter
        RBloomFilter<Object> bloomFilter = redissonClient.getBloomFilter("xx");

        bloomFilter.tryInit(1000000,0.001);


        //存数据
        bloomFilter.add("1");
        bloomFilter.add("2");
        bloomFilter.add("3");
        bloomFilter.add("5");
        bloomFilter.add("4");
        bloomFilter.add("6");
        bloomFilter.add("7");


        return bloomFilter;
    }
}
